package cn.edu.ldu.protocol;

import cn.edu.ldu.views.controller.MainUIController;
import lombok.Data;

import javax.swing.*;
import java.io.Serializable;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.net.DatagramPacket;

@Data
public class Protocol implements Serializable {
    private static final long serialVersionUID = 1L;

    private String key;
//    private byte[] data;ke
    private String data;
    private DatagramPacket packet;
    private String token;

    public void key(){
        //解决视图结果
        if(data == null){
            JOptionPane.showMessageDialog(MainUIController.getMainUI(), key);
            return;
        }
        try{
            Class cls = Class.forName("cn.edu.ldu.protocol."+this.getKey());
            //protocol.loginsucces
            Constructor con = cls.getConstructor(Protocol.class);
            con.newInstance(this);
        } catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException | InstantiationException | InvocationTargetException e) {
            e.printStackTrace();
        }
    }

}
